package com.jingdianjichi.subject.application.controller;

import com.jingdianjichi.subject.service.ElasticsearchService;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/elasticsearch")

public class ElasticsearchController {
    @Resource
    private ElasticsearchService service;


    @RequestMapping("/getEmployeeIndex")
    public CreateIndexResponse getEmployeeIndex(@RequestParam String indexName) {
        return  service.getEmployeeIndex(indexName);
    }

    @RequestMapping("/deleteEmployeeIndex")
    public void deleteEmployeeIndex(@RequestParam String indexName) {
        service.deleteEmployeeIndex(indexName);
    }

    /**
     * 将sql中数据查询并封装到es中
     * @param indexName
     * @param id
     */
    @RequestMapping("/addEmployeeIndexDocument")
    public void addEmployeeIndexDocument(@RequestParam String indexName,@RequestParam String id) {
            service.addEmployeeIndexDocument(indexName,id);
    }
    /**
     * 查询es文档中的数据
     */
    @RequestMapping("/getEmployeeIndexDocument")
    public void getEmployeeIndexDocument(@RequestParam String indexName,@RequestParam String id) {
        service.getEmployeeIndexDocument(indexName,id);
    }

    /**
     * 更新es文档中的数据
     */
    @RequestMapping("/updateEmployeeIndexDocument")
    public void updateEmployeeIndexDocument(@RequestParam String indexName,@RequestParam String id) {
        service.updateEmployeeIndexDocument(indexName,id);
    }

    /**
     * 删除es文档中的数据
     */
    @RequestMapping("/deleteEmployeeIndexDocument")
    public void deleteEmployeeIndexDocument(@RequestParam String indexName,@RequestParam String id) {
        service.deleteEmployeeIndexDocument(indexName,id);
    }
    /**
     * 批量插入数据到es文档中
     */
    @RequestMapping("/addEmployeeIndexDocumentBatch")
    public void addEmployeeIndexDocumentBatch(@RequestParam String indexName) {
        service.addEmployeeIndexDocumentBatch(indexName);
    }
    /**
     * 查询全部文档数据
     */
    @RequestMapping("/getEmployeeIndexDocumentAll")
    public void getEmployeeIndexDocumentAll(@RequestParam String indexName) {
        service.getEmployeeIndexDocumentAll(indexName);
    }


}
